package ar.edu.itba.it.pdc.utils;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import ar.edu.itba.it.pdc.protocol.email.Header;

public class TimeConverter {

	private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy");
	private static final DateTimeFormatter fullfmt = DateTimeFormat.fullDate();
	private static final DateTimeFormatter headerFmt = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z");
	private static final DateTimeFormatter hourFmt = DateTimeFormat.forPattern("HH:mm:ss");
	
	public static String printDateTime(DateTime time) {
		return fmt.print(time.getMillis());
	}
	
	public static DateTime parseDateTime(String dateTime) {
		return fmt.parseDateTime(dateTime);
	}
	
	public static DateTime parseFullDateTime(String fullDateTimeText) {
		return fullfmt.parseDateTime(fullDateTimeText);
	}
	
	public static String printFullDateTimeText(String fullDateTimeText) {
		return printDateTime(parseFullDateTime(fullDateTimeText));
	}
	
	public static DateTime parseDateHeaderTime(Header header) {
		String h = header.getValue().trim().replace(" (PST)", "");
		return headerFmt.parseDateTime(h);
	}
	
	public static DateTime parseHour(String hour) {
		return hourFmt.parseDateTime(hour);
	}
	
	
}
